import os
from multiprocessing import Pool 


input_files = os.listdir("./12.tree_concept_parent")

output_dir = "./13.tree_annotation_to_table"
os.makedirs(output_dir, exist_ok=True)


def exec(add_pfam_tables, cluster_tables, concept_trees, output_file_path):
    cmd = f"python 13.tree_annotation_to_table.py -add_pfam_table {add_pfam_tables} -cluster_table {cluster_tables} -concept_tree {concept_trees} -output {output_file_path}"
    os.system(cmd)
    
tasks = []
for file in input_files:
    add_pfam_tables = os.path.join("./03.cluster_add_pfam_info",  file.split(".")[0] + "___add_pfam_info.xlsx")
    cluster_tables = os.path.join("./05.gene_cluster_glm_summary_1", file.split(".")[0] + ".xlsx")
    concept_trees = os.path.join("./12.tree_concept_parent",  file.split(".")[0] + ".json")
    output_file_path = os.path.join("./13.tree_annotation_to_table", file.split(".")[0] + ".xlsx")
    tasks.append((add_pfam_tables, cluster_tables, concept_trees, output_file_path))

# for i in tasks[0:2]:
#     exec(i[0], i[1], i[2], i[3])

with Pool(250) as pool:
    pool.starmap(exec, tasks)